package com.xqboss.web.controller.game;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xqboss.apps.domain.game.Game;
import com.xqboss.apps.dto.PageDto;
import com.xqboss.apps.dto.game.GameDto;
import com.xqboss.apps.service.game.GameService;
import com.xqboss.apps.vo.game.materialStrike.GameVo;
import com.xqboss.common.annotation.Log;
import com.xqboss.common.core.domain.R;
import com.xqboss.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 这个controller可以定义游戏的一些公共接口
 *
 * @author ljh
 * @date 2024-1-30
 */
@RestController
@RequestMapping("/web/game")
@Api(tags = "游戏后台管理")
public class WebGameController {

    @Autowired
    private GameService gameService;

    @PreAuthorize("@ss.hasPermi('web:game:list')")
    @ApiOperation("游戏列表页")
    @GetMapping("list")
    public R<List<Game>> list(@Validated PageDto dto,@ApiParam(name = "name",value = "游戏名称",readOnly = false) String name) {
        IPage<Game> page =  gameService.webGameList(dto,name);
        return R.ok(page.getRecords(),page.getTotal());
    }

    @PreAuthorize("@ss.hasPermi('web:game:saveOrEdit')")
    @Log(title = "新增或编辑游戏", businessType = BusinessType.UPDATE)
    @ApiOperation("新增或编辑游戏")
    @PostMapping("saveOrEdit")
    public R<String> saveOrEdit(@Validated @RequestBody GameDto dto) {
        return gameService.saveOrEdit(dto);
    }

    @PreAuthorize("@ss.hasPermi('web:game:delete')")
    @Log(title = "删除游戏", businessType = BusinessType.DELETE)
    @ApiOperation("删除游戏")
    @PostMapping("delete")
    public R<String> delete(@ApiParam(name = "gameId",value = "游戏id",readOnly = true) Long gameId) {
        return gameService.delete(gameId);
    }
}
